#include "networkmanager.h"
#include "qwebsecurityorigin.h"
#include "qstringlist.h"

QNetworkReply *NetworkManager::createRequest(QNetworkAccessManager::Operation op,
	const QNetworkRequest &request, QIODevice *outgoingData) {
	QUrl requestUrl = request.url();
	QString requestScheme = requestUrl.scheme();
	if (QWebSecurityOrigin::localSchemes().indexOf(requestScheme) != -1) {
		return this->createRequest(request.url());
	} else return QNetworkAccessManager::createRequest(op, request, outgoingData);
}

/* public declarations */

QByteArray NetworkManager::get(QString url) {
	QNetworkReply* reply = this->createRequest(GetOperation, QNetworkRequest(QUrl(url)));
	reply->open(QIODevice::ReadOnly);
	QByteArray result(reply->readAll());
	reply->close();
	delete reply;
	return result;
}
